package tmproject.hlhj.fhp.cartrans.modules

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.cartrans.http.Apis
import tmproject.hlhj.fhp.cartrans.http.BaseObserver
import tmproject.hlhj.fhp.cartrans.http.LoadingAction
import tmproject.hlhj.fhp.cartrans.javaBean.BaseBean
import tmproject.hlhj.fhp.cartrans.javaBean.ExamRuleBean
import tmproject.hlhj.fhp.cartrans.utils.LoadingUtil

/**
 * Created by Administrator on 2018/8/28/028.
 */
class ExamRuleModule :BaseModule {
    var listener:OnExamRuleListener?=null

    fun getRule(c:Context,token:String?,id:Int){
        Apis.getExamRule(token,id)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<ExamRuleBean>>(c){
                                override fun failed(e: Throwable?) {
                                }

                                override fun onError(e: Throwable) {
                                    LoadingUtil.hideLoading()
//                                    super.onError(e)
                                }
                                override fun httpSuccess(t: Response<ExamRuleBean>) {
                                    listener?.getRule(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
    }

    interface OnExamRuleListener{
        fun getRule(examBean: ExamRuleBean)
    }
}